<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./axios.min.js"></script>
</head>

<body>
    <button id="btn1">发起get请求</button>
    <button id="btn2">发起post请求</button>
    <button id="btn3">发起axios请求</button>
    <button id="btn4">发起请求</button>

    <script>
        document.querySelector('#btn1').addEventListener('click', function() {
            var url = 'http://www.liulongbin.top:3006/api/get'
            var paramObj = {
                name: 'zs',
                age: 20
            }
            axios.get(url, {
                paramObj
            }).then(function(res) {
                console.log(res.data);
            })
        })

        document.querySelector('#btn2').addEventListener('click', function() {
            var url = 'http://www.liulongbin.top:3006/api/post'
            var dataObj = {
                address: '北京',
                localtion: '顺义区'
            }
            axios.post(url, {
                dataObj
            }).then(function(res) {
                console.log(res.data);
            })
        })

        document.querySelector('#btn3').addEventListener('click', function() {
            var url = 'http://www.liulongbin.top:3006/api/get'
            var paramData = {
                name: 'zs',
                age: 20
            }
            axios({
                method: 'GET',
                url: url,
                params: paramData
            }).then(function(res) {
                console.log(res.data);
            })
        })

        document.querySelector('#btn4').addEventListener('click', function() {
            var url = 'http://www.liulongbin.top:3006/api/post'
            axios({
                method: 'POST',
                url: url,
                data: {
                    name: 'haha',
                    age: 19,
                    gender: '女'
                }
            }).then(function(res) {
                console.log(res.data);
            })
        })
    </script>
</body>

</html>